package com.charlotte.study.gupao.strategy.pay;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author junjie.ding
 * @date 2020/3/16
 */
public class PaymentStrategy {

    private static final String ALI_PAY = "alipay";

    private static final String JD_PAY = "jdpay";

    private static final String UNION_PAY = "unionpay";

    private static final String DEFAULT_PAY = ALI_PAY;

    private static Map<String, Payment> paymentMap = new ConcurrentHashMap<>(4);

    static {
        paymentMap.put(ALI_PAY, new ALiPayment());
        paymentMap.put(JD_PAY, new JDPayment());
        paymentMap.put(UNION_PAY, new UnionPayment());
        paymentMap.put(DEFAULT_PAY, new ALiPayment());
    }

    public static Payment getPayment(String payment){
        if(paymentMap.containsKey(payment)){
            return paymentMap.get(payment);
        }
        return paymentMap.get(DEFAULT_PAY);
    }
}
